﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace SageKing.Core.Extensions;

public static class HttpClientExts
{
    /// <summary>
    /// http://127.0.0.1
    /// to
    /// http://127.0.0.1/
    /// </summary>
    /// <param name="client"></param>
    /// <exception cref="ArgumentNullException"></exception>
    /// <exception cref="InvalidOperationException"></exception>
    public static void CheckBaseAddress(this HttpClient client)
    {
        if (client == null)
        {
            throw new ArgumentNullException(nameof(client), "HttpClient cannot be null.");
        }
        if (client.BaseAddress == null)
        {
            throw new InvalidOperationException("HttpClient's BaseAddress must be set before making requests.");
        }
        client.BaseAddress = new Uri(client.BaseAddress.AbsoluteUri.TrimEnd('/') + '/');
    }
}
